package com.studyv3.test.controller.productsbuy;

import com.studyv3.common.core.controller.BaseController;
import com.studyv3.common.core.domain.AjaxResult;
import com.studyv3.common.core.page.TableDataInfo;
import com.studyv3.test.domain.ApplyProduct;
import com.studyv3.test.service.ApplyApprovalService;
import com.studyv3.test.service.ApplyProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/approval/")
public class ApprovalController extends BaseController {
    @Autowired
    ApplyProductService applyProductService;
    @Autowired
    ApplyApprovalService applyApprovalService;

    @PostMapping("agree")
    public AjaxResult agree(@RequestBody ApplyProduct applyProduct) {

        applyProduct.setFlag(1);
        applyApprovalService.agreeOrReject(applyProduct);

        return applyApprovalService.agreeOrReject(applyProduct);
    }

    @PostMapping("reject")
    public AjaxResult reject(@RequestBody ApplyProduct applyProduct) {

        applyProduct.setFlag(0);

        return applyApprovalService.agreeOrReject(applyProduct);
    }
    /*
     * 待审数量
     * */
    @GetMapping("myapprovalnum")
    public Integer myapprovalNum(ApplyProduct applyProduct) {
        applyProduct.setFlag(2);
        applyProduct.setDeleted(0);
        List<ApplyProduct> list = applyProductService.selectApplyProductList(applyProduct);
        return list.size();
    }

    /*
    * 我的已审
    * */
    @GetMapping("myapproval")
    public TableDataInfo myapproval(ApplyProduct applyProduct) {
        applyProduct.setApprovalUser(getUserId().intValue());
        applyProduct.setFlag(2);
        applyProduct.setDeleted(0);
        startPage();
        List<ApplyProduct> list = applyProductService.selectApplyByMeProductList(applyProduct);
        return getDataTable(list);
    }

}
